package org.threebitsoftware.tbb.Contact_GUI;

import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.BufferedOutputStream;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.Vector;

import javax.imageio.ImageIO;
import javax.imageio.ImageReadParam;
import javax.imageio.ImageReader;
import javax.imageio.stream.ImageInputStream;
import javax.swing.JOptionPane;

import org.apache.log4j.Logger;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.threebitsoftware.dao.generated.Contactphoto;
import org.threebitsoftware.tbb.dao.Address;
import org.threebitsoftware.tbb.dao.Contact;
import org.threebitsoftware.tbb.dao.EmailAddress;
import org.threebitsoftware.tbb.dao.PhoneNumber;
import org.threebitsoftware.tbb.dao.TagForContact;
import org.threebitsoftware.tbb.dao.bridge.TagBridge;
import org.threebitsoftware.tbb.engine.EngineUtil;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.graphics.PaletteData;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.RGB;
import org.threebitsoftware.tbb.module.map.*;
import com.swtdesigner.SWTResourceManager;

import org.eclipse.swt.events.FocusEvent;
import org.eclipse.swt.events.FocusListener;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.MenuAdapter;
import org.eclipse.swt.events.MenuEvent;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.SelectionListener;


public class ContactFormGUI{

	private static Logger logger = Logger.getLogger(ContactFormGUI.class);
	protected Shell shlContactManagementSoftware_;
	private final FormToolkit formToolkit = new FormToolkit(Display.getDefault());
	private static int loggedinAppUserid = -1;
	private Display display;
//	
//	private boolean userLoginStatusHistory_ = false;
	private static boolean isLoginStatus_ = false;


	private Text contactSerchText_;
	private Text addressText_;
	private Text nameText_;
	private Text telephoneText_;
	private Text emailText_;
	
	public Tree contactGroupTreex_;
	TreeItem selectedTreeItem;
	
	private Contact currentlySelectedContact = null;
	
	private ArrayList<Contact> contactArrayList_ = new ArrayList<Contact>();
	Vector<Address> addressVectorList_ = new Vector<Address>();
	Vector<EmailAddress> emailAddressvectorList_ = new Vector<EmailAddress>();
	Vector<PhoneNumber> phoneVectorList_ = new Vector<PhoneNumber>();

	private Combo comboEmailList;
	private Combo comboAddressList;
	private Combo comboTelephoneList;
	private Combo comboContactSyncType;
	

	private Button btnDeleteGroup_;
	private Button btnDoNotDownload;
	
	private MenuItem mntmSync;

	private Label lblDestinationAddress;
	
	protected Image contactPhoto;
	private Canvas photoHolderCanvasx_;
	private Text txtEnterDestinationAddress;
	
	public static boolean isLoginStatus() {
		return isLoginStatus_;
	}

	public static void setLoginStatus(boolean isLoginStatus) {
		isLoginStatus_ = isLoginStatus;
	}
	
	public ContactFormGUI() {

	}

	/**
	 * Launch the application.
	 * 
	 * @param args
	 */
	public static void main(String[] args) {
		try {
			
			// NOTE: This is just a temp fix so that we can view the form in
			// Design view.
			// To view this form in design view un-comment the lines below.
//			ContactFormGUI tempwindow = new ContactFormGUI();
//			tempwindow.open();



			// Open the login screen first.

			Shell contactFromGUIShell = new Shell();
			contactFromGUIShell.setSize(537, 0);
			
			UserProfileFormGUI userProfileFormGUI = new UserProfileFormGUI(contactFromGUIShell, 1);
			userProfileFormGUI.open();
//

			// if login status succeeds show the contact form. If not pop a
			// message "Invalid login."
			if (ContactFormGUI.isLoginStatus() == true) {
				loggedinAppUserid = UserProfileFormGUI.getUsersLoginID_();
				
				ContactFormGUI window = new ContactFormGUI();
				window.open();
				
			}

			else {
				logger.info("\n Invalid users credentials... Please check username/password....");
				System.out.println("\n Invalid users credentials... Please check username/password....");
			}

		} catch (Exception e) {
			logger.error("Threw an exception: " + e.getMessage());
			e.printStackTrace();
		}
	}

	/**
	 * Open the window.
	 */
	public void open() {

		//Getting all the contact from the Database. 
		createContactArrayList(EngineUtil.getAllContacts());
		
//		testContactList();

		display = Display.getCurrent();
		createContents();
		shlContactManagementSoftware_.open();
		shlContactManagementSoftware_.layout();
		while (!shlContactManagementSoftware_.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
	}

	/**
	 * Create contents of the window.
	 */
	protected void createContents() {
		shlContactManagementSoftware_ = new Shell();
		
		shlContactManagementSoftware_.setBackground(SWTResourceManager
				.getColor(SWT.COLOR_LIST_SELECTION_TEXT));
		shlContactManagementSoftware_.setToolTipText("Delete Photo");
		shlContactManagementSoftware_.setSize(815, 666);
		shlContactManagementSoftware_.setText("Contact Management Software");
		{
			Menu menuContact = new Menu(shlContactManagementSoftware_, SWT.BAR);
			shlContactManagementSoftware_.setMenuBar(menuContact);
			{
				MenuItem mntmFile = new MenuItem(menuContact, SWT.CASCADE);
				mntmFile.setText("File");
				{
					Menu menu_1 = new Menu(mntmFile);
					mntmFile.setMenu(menu_1);
					
					{// This is menu for adding New Contact
						MenuItem mntmNewContact = new MenuItem(menu_1, SWT.NONE);
						mntmNewContact
								.addSelectionListener(new SelectionAdapter() {
									@Override
									public void widgetSelected(SelectionEvent e) {
										System.out
												.println("Sub Menu New Contact Clicked");
										AddContactMenu_GUI submenu_newContact = new AddContactMenu_GUI(
												shlContactManagementSoftware_,
												1);
										submenu_newContact.open();
									}
								});
						mntmNewContact.setText("New Contact");
					}
					
					{// This is to close application
						MenuItem mntmClose = new MenuItem(menu_1, SWT.NONE);
						mntmClose.setText("Close");
						mntmClose.addSelectionListener(new SelectionAdapter() {
							
							@Override
							public void widgetSelected(SelectionEvent arg0) {
								shlContactManagementSoftware_.close();
							}

						});
					}
				}
			}
			{
				MenuItem mntmEdit = new MenuItem(menuContact, SWT.CASCADE);
				mntmEdit.setText("Photo");
				{// This is to edit the contacts
					Menu menu_1 = new Menu(mntmEdit);
					mntmEdit.setMenu(menu_1);
					{// This will upload the contact
						MenuItem mntmImportPhoto = new MenuItem(menu_1,
								SWT.CASCADE);
						mntmImportPhoto.setSelection(true);

						mntmImportPhoto.setText("Import Photo");
						
						mntmImportPhoto.addSelectionListener(new SelectionAdapter() {
							@Override
							public void widgetSelected(SelectionEvent e) {
								System.out.println("Importing photo for " + currentlySelectedContact.toString());
								PhotoImport contactPhotoToBeImported = new PhotoImport(shlContactManagementSoftware_, 1, currentlySelectedContact);
								contactPhotoToBeImported.open();
								resetCompleteGUI();
							}
						});
						
					}
					{// This will delete the photo
						MenuItem mntmExportPhoto = new MenuItem(menu_1,
								SWT.NONE);
						mntmExportPhoto.setText("Export Photo");
						
						
						mntmExportPhoto.addSelectionListener(new SelectionAdapter() {
							@Override
							public void widgetSelected(SelectionEvent e) {
								System.out.println("Exporting photo for " + currentlySelectedContact.toString());
								PhotoExport contactToBeExported = new PhotoExport(shlContactManagementSoftware_, 1, currentlySelectedContact);
								contactToBeExported.open();
								resetCompleteGUI();
							}
						});
						

					}
				}
			}
			{
				MenuItem mntmImportexport = new MenuItem(menuContact, SWT.CASCADE);
				mntmImportexport.setText("Import/Export");
				{// This will export/import the contact
					Menu menu_1 = new Menu(mntmImportexport);
					mntmImportexport.setMenu(menu_1);
					{// This will Import/Export a vcard
						MenuItem mntmImportVcard = new MenuItem(menu_1,
								SWT.NONE);
						mntmImportVcard.addSelectionListener(new SelectionAdapter() {
							@Override
							public void widgetSelected(SelectionEvent e) {
								
								System.out.println("Importing VCard/Simple text");
								FileImport_GUI submenu_importContact = new FileImport_GUI(
										shlContactManagementSoftware_,
										1);
								submenu_importContact.open();
								resetCompleteGUI();
								
							}
						});
						mntmImportVcard.setText("Import V-Card/Simple Text");
					}
					{
						MenuItem mntmExportVcard = new MenuItem(menu_1,
								SWT.NONE);
						mntmExportVcard.addSelectionListener(new SelectionAdapter() {
							@Override
							public void widgetSelected(SelectionEvent e) {
								System.out.println("I am exporting VCard...");
								FileExport_GUI submenu_exportContact = new FileExport_GUI(
										shlContactManagementSoftware_,
										1, contactArrayList_);
								submenu_exportContact.open();
							}
						});
						mntmExportVcard.setText("Export V-Card/Simple Text");
					}
				}
			}
			{// This will add/sync ... users.
				MenuItem mntmUsers = new MenuItem(menuContact, SWT.CASCADE);
				mntmUsers.setText("Users");
				{
					Menu menu_1 = new Menu(mntmUsers);
					mntmUsers.setMenu(menu_1);
					{
						mntmSync = new MenuItem(menu_1, SWT.NONE);
						mntmSync.addSelectionListener(new SelectionAdapter() {
							@Override
							public void widgetSelected(SelectionEvent e) {
								System.out.println("Google syncing login page...");
								Sync_WebService_GUI submenu_syncContactLogin = new Sync_WebService_GUI(
										shlContactManagementSoftware_,
										1, loggedinAppUserid);
								submenu_syncContactLogin.open();
								resetCompleteGUI();
							}
						});
						mntmSync.setText("Sync");
					}
					{
						MenuItem mntmProfile = new MenuItem(menu_1, SWT.NONE);
						mntmProfile
								.addSelectionListener(new SelectionAdapter() {
									@Override
									public void widgetSelected(SelectionEvent e) {
										
										
										UserProfileFormGUI d = new UserProfileFormGUI(
												shlContactManagementSoftware_,1);
										
										// If the user goes to the login screen
										// after logging into the Application
										// show the Edit button.
										d.setLoginStatus(true);
										d.open();
									}
								});
						mntmProfile.setText("Profile");
					}
				}
			}
			{// Help options
				MenuItem mntmHelp = new MenuItem(menuContact, SWT.CASCADE);
				mntmHelp.setText("Help?");
				{
					Menu menu_1 = new Menu(mntmHelp);
					mntmHelp.setMenu(menu_1);
					{
						MenuItem mntmHelpContents = new MenuItem(menu_1,
								SWT.NONE);
						mntmHelpContents.setText("Help Contents");
					}
					{
						MenuItem mntmSearch = new MenuItem(menu_1, SWT.NONE);
						mntmSearch.setText("Search");
					}
					{
						MenuItem mntmAboutMe = new MenuItem(menu_1, SWT.NONE);
						mntmAboutMe.setText("About Me...");
					}
				}
			}
		}
		{
			Menu menu = new Menu(shlContactManagementSoftware_);
			shlContactManagementSoftware_.setMenu(menu);
		}
		{
			Group grpContacts = new Group(shlContactManagementSoftware_,
					SWT.NONE);
			grpContacts.setText("Contacts");
			grpContacts.setBackground(SWTResourceManager
					.getColor(SWT.COLOR_WIDGET_BACKGROUND));
			grpContacts.setBounds(0, 40, 314, 580);
			{
				Label label = new Label(grpContacts, SWT.SEPARATOR
						| SWT.HORIZONTAL);
				label.setBounds(0, 270, 288, -6);
			}
			
			
			{//---------------------------------------------->
				//This is search button
				Button btnSort = formToolkit.createButton(grpContacts,
						"&Search", SWT.NONE);
				btnSort
						.setImage(SWTResourceManager
								.getImage("C:\\Documents and Settings\\pramakrishnan\\Desktop\\SW Project\\filter.png"));
				btnSort.setBounds(10, 49, 84, 23);
				
				btnSort.addSelectionListener(new SelectionAdapter() {
					
					@Override
					public void widgetSelected(SelectionEvent arg0) {
						System.out.println("Searching for contacts" + contactSerchText_.getText());
						String searchString = contactSerchText_.getText();
						
						//This is a test argument
						getSearchContact(searchString);
						
					}

				});
				
			}

			{// This is random button. Yet to be decided.
				Button btnAddNewGroup = formToolkit.createButton(grpContacts,
						"Add New &Group", SWT.NONE);
				btnAddNewGroup.setBounds(10, 20, 84, 23);
			}

			// Contact Group Tree------------------------>
			{
				// boolean contactGroupSelected = false;
				contactGroupTreex_ = new Tree(grpContacts, SWT.BORDER);
				
				TreeItem contactGroupItem_ = null;

				contactGroupTreex_.setBounds(10, 78, 288, 475);
				formToolkit.adapt(contactGroupTreex_);
				formToolkit.paintBordersFor(contactGroupTreex_);
				{
					
					String[] contactGroupArray = EngineUtil.getDistinctContact();
			
					
					// Add the Contact Group Name in the
					// Tree------------------------------>
					for (String currentContactGroup : contactGroupArray) {

						// contactGroupItem_.setText(contactArrayPerGroup_.get(0).getTags().firstElement());
						contactGroupItem_ = new TreeItem(contactGroupTreex_,
								SWT.NONE);
						contactGroupItem_.setExpanded(true);

						contactGroupTreex_.setData("ContactGroupTree",
								contactGroupItem_);
						
						//naming the Contact Group.
						contactGroupItem_.setText(currentContactGroup);

						Enumeration enumerateContact = Collections
								.enumeration(contactArrayList_);

					
						//All the contacts in a Contact Group
						ArrayList<Contact> contactsPerGroup = new ArrayList<Contact>();
						
						
						//iterate through each Contact and add the matching Contact to the Contact Group. 
						while (enumerateContact.hasMoreElements()) {
							Contact currentContact = (Contact) enumerateContact
									.nextElement();

							if (findTagMatch(currentContact.getTags(),
									currentContactGroup)) {//add the Contact to the matching Contact Group

								contactsPerGroup.add(currentContact);

							}
							else
							{
								logger.warn("Contact is missing group? : " + currentContact.toString());
							}
						}
						
						//Add the Contact for a Contact Group in the Contact Group Tree
							createContactItems(contactGroupItem_, contactsPerGroup);
							
					}
					
				}

				// Display the Contact Information in the GUI when a Contact is
				// clicked from the Tree
				// ----------------------------------------->
				contactGroupTreex_.addSelectionListener(new SelectionAdapter() {
					@Override
					public void widgetSelected(SelectionEvent e) {

						selectedTreeItem = (TreeItem) e.item;
						String selectedContactName = selectedTreeItem.getText();
						Class selectedContactItemData = selectedTreeItem.getData(selectedContactName).getClass();
						
						if (selectedTreeItem.getItemCount() == 0  && !selectedContactItemData.getName().equals("java.util.ArrayList")) {
							System.out.println("This is contact"
									+ selectedTreeItem.getData(selectedTreeItem
											.getText()));
							
							//Enable the Drop down only if a Contact is clicked. 
							comboEmailList.setEnabled(true);
							comboAddressList.setEnabled(true);
							comboTelephoneList.setEnabled(true);
							
							Contact selectedContact = (Contact) selectedTreeItem
									.getData(selectedTreeItem.getText());
							
							//Just to keep a reference about the focused Contact currently on the GUI.
							currentlySelectedContact = selectedContact;

							nameText_.setText(selectedContact.getFirstName()
									+ " " + selectedContact.getLastName());

							// Reset the list box to show the Lists for another
							// Contact.
							comboEmailList.removeAll();
							comboAddressList.removeAll();
							comboTelephoneList.removeAll();
							
							
							String tempImagePath = "./mytemp.gif";	
							String tempBlankScreen = "./blank.gif";
							
							//EngineUtil to get the photo for the Contact. 	
							Contactphoto selectedContactPhoto = EngineUtil.getPhotoExport(selectedContact,"org.threebitsoftware.tbb.module.photo.ContactPhoto", tempImagePath);
							
			

						
							if (selectedContactPhoto!=null){//Photo exist for the Contact
								logger.debug("Displaying photo for Contact: " + selectedContact.toString());
								selectedContact.setPhoto(selectedContactPhoto.getBlobPhoto());
								photoHolderCanvasx_.redraw();  
								contactPhoto = new Image(display, tempImagePath);
								logger.debug("Photo displayed for Contact: " + selectedContact.toString());
								
							} else if (selectedContactPhoto==null){//Photo does not exist for the Contact
								logger.debug("Photo does not exist for Contact: " + selectedContact.toString());
//								photoHolderCanvasx_.redraw();
								photoHolderCanvasx_.redraw();  
								contactPhoto = new Image(display, tempBlankScreen);
								
							}
		
							
							populateDropDownList(comboEmailList, selectedContact.getEmails());
							populateDropDownList(comboAddressList, selectedContact.getAddresses());
							populateDropDownList(comboTelephoneList, selectedContact.getPhoneNumbers());
							

						} else if (selectedTreeItem.getItemCount() != 0) {

							System.out.println("This is an arraylist maybe a Contact group "
											+ selectedTreeItem);
						} else if (selectedContactItemData.getName().equals("java.util.ArrayList")){
							logger.info("Contact Group "+ selectedTreeItem.getText() + "is empty");
							System.out.println("Contact Group "+ selectedTreeItem.getText() + " is empty");
						}

						logger.debug("Contact group selected: "
								+ selectedTreeItem.getText());

					}
				});

				contactGroupTreex_.setRedraw(true);
			}

			// Searching for Contacts-------------------------------------->
			{
				contactSerchText_ = new Text(grpContacts, SWT.BORDER);
				contactSerchText_.setBounds(106, 51, 192, 19);
				formToolkit.adapt(contactSerchText_, true, true);
				
				
			}
		}
		{
			Group contactInformationDisplay_ = new Group(
					shlContactManagementSoftware_, SWT.NONE);
			contactInformationDisplay_.setBackground(SWTResourceManager
					.getColor(SWT.COLOR_WIDGET_BACKGROUND));
			contactInformationDisplay_.setBounds(314, 40, 493, 580);
			{// These are label which display detailed information of the
				// contacts.
				CLabel lblName_ = new CLabel(contactInformationDisplay_,
						SWT.NONE);
				lblName_.setBackground(SWTResourceManager
						.getColor(SWT.COLOR_GRAY));
				lblName_.setBounds(10, 28, 81, 19);

				//Contact Name
				lblName_.setText("Name:");
			}
			/*{
				CLabel lblAddress_ = new CLabel(contactInformationDisplay_,
						SWT.NONE);
				lblAddress_.setBackground(SWTResourceManager
						.getColor(SWT.COLOR_GRAY));
				lblAddress_.setBounds(10, 53, 81, 19);

				//Contact Address
				lblAddress_.setText("Address:");
			}
			{
				CLabel lblTelephone_ = new CLabel(contactInformationDisplay_,
						SWT.NONE);
				lblTelephone_.setBackground(SWTResourceManager
						.getColor(SWT.COLOR_GRAY));
				lblTelephone_.setBounds(10, 103, 81, 19);

				//Contact Telephone
				lblTelephone_.setText("Telephone: ");
			} */
			{// This will force that contact will not be downloaded. May be by
				// greying out the upload button
				btnDoNotDownload = new Button(
						contactInformationDisplay_, SWT.CHECK);

				
				btnDoNotDownload.addSelectionListener(new SelectionAdapter() {
					@Override
					public void widgetSelected(SelectionEvent e) {
						System.out.println("User cannot sync.");
					
						
						if (btnDoNotDownload.getSelection()){
							logger.info("Disabling the Sync Menu Item");
							System.out.println("Disabling the Sync Menu Item");
							mntmSync.setEnabled(false);
							
						} else  if (!btnDoNotDownload.getSelection()){
							logger.info("Enabling the Sync Menu Item");
							System.out.println("Enabling the Sync Menu Item");
							mntmSync.setEnabled(true);
						}

						
//						//user cannot choose Down and Both option if the "do not download check box is clicked"
//						if (btnDoNotDownload.getSelection()){
//						comboContactSyncType.remove(1);
//						comboContactSyncType.remove(1);
//						comboContactSyncType.select(0);
//					} else if (!btnDoNotDownload.getSelection()){
//						comboContactSyncType.add("Down", 1);
//						comboContactSyncType.add("Both", 2);
//						comboContactSyncType.select(0);
//					}
					}
				});
				btnDoNotDownload.setBounds(10, 500, 183, 16);
				btnDoNotDownload.setText("DO NOT SYNC CONTACTS");
			}

			{// This is to delete a contact-------------------------------->
				Button btnDeleteContact_ = new Button(
						contactInformationDisplay_, SWT.NONE);
				//hiding for now
				btnDeleteContact_.setVisible(false);
				
				btnDeleteContact_.addSelectionListener(new SelectionAdapter() {

					@Override
					public void widgetSelected(SelectionEvent e) {
						
						Contact selectedContact = (Contact) selectedTreeItem
						.getData(selectedTreeItem.getText());
						
						logger.info("Deleting a contact..");
						
						try {
							EngineUtil.deleteContact(selectedContact);
						} catch (SQLException contactDeleteError) {
							System.out.println("Error deleting Contact.");
							contactDeleteError.printStackTrace();
						}
						
						resetCompleteGUI();
					}
				});

				btnDeleteContact_.setBounds(405, 500, 68, 23);
				btnDeleteContact_.setText("Delete");
			}
			{// This is to modify contact
				Button btnModifyContact_ = new Button(
						contactInformationDisplay_, SWT.NONE);
				btnModifyContact_.setBounds(331, 551, 68, 23);
				btnModifyContact_.setText("Modify");
				
				//can not figure out where button actionlistner is?
				btnModifyContact_.setVisible(false);
			}
			{// This is where the Contact photo will be plugged in
				photoHolderCanvasx_ = new Canvas(
						contactInformationDisplay_, SWT.BORDER
								| SWT.NO_BACKGROUND | SWT.NO_MERGE_PAINTS);
				
				photoHolderCanvasx_.addPaintListener(new PaintListener() {
					public void paintControl(PaintEvent event) {
						System.out.println("Displayin Image.");
						if (contactPhoto != null) {
							event.gc.drawImage(contactPhoto, 0, 0);
						} else if (contactPhoto==null){
							
						}

					}
				});
				photoHolderCanvasx_.setBounds(305, 28, 168, 135);
				formToolkit.adapt(photoHolderCanvasx_);
				formToolkit.paintBordersFor(photoHolderCanvasx_);
			}
			{// This is to map the Contacts based on the address.

				Button btnContactMapLocation_ = new Button(
						contactInformationDisplay_, SWT.NONE);
				btnContactMapLocation_
						.addSelectionListener(new SelectionAdapter() {
							@Override
							public void widgetSelected(SelectionEvent e) {
								try {

									GoogleMapUrl gMapUrl = new GoogleMapUrl();
									
									
									// gMapUrl.formatUrl(usr'saddress, contact's
									// address);
									
									//ASK: 1. I want the logged in user's start address. 
									String loggedInUserStartAddress = txtEnterDestinationAddress.getText();
									
									
									String contactDestStreetName = addressVectorList_.lastElement().getStreet1();
									String contactDestCityName = addressVectorList_.lastElement().getCity();
									String contactDestState = addressVectorList_.lastElement().getProvince();
									String contactDestZipCode = addressVectorList_.lastElement().getZipCode();
									String contactformattedDestinationAddress = contactDestStreetName +" " + contactDestCityName +", "  + contactDestState + " "  + contactDestZipCode;
									
									//Google address format sample: "77 Massachusetts Ave, Boston, Suffolk, Massachusetts 02115"
									gMapUrl.formatUrl(loggedInUserStartAddress, contactformattedDestinationAddress);
									T2Browser mapView = new T2Browser();
									mapView.setUrl(gMapUrl.toString());
									mapView.open();

								} catch (Exception ex) {

								}
							}
						});

				btnContactMapLocation_.setBounds(358, 169, 68, 23);
				btnContactMapLocation_.setText("MAP");

			}
			{
				comboContactSyncType = new Combo(contactInformationDisplay_, SWT.READ_ONLY);
				comboContactSyncType.setItems(new String[] {"Up", "Down", "Both"});

				comboContactSyncType.setVisibleItemCount(3);
				comboContactSyncType.setBounds(199, 500, 87, 20);
				formToolkit.adapt(comboContactSyncType);
				formToolkit.paintBordersFor(comboContactSyncType);
				comboContactSyncType.select(0);
				comboContactSyncType.setVisible(false);
			}
			/*{
				addressText_ = new Text(contactInformationDisplay_, SWT.BORDER
						| SWT.MULTI);
				addressText_.setEditable(false);
				addressText_.setBounds(127, 53, 159, 19);
				formToolkit.adapt(addressText_, true, true);
			}*/
			{
				nameText_ = new Text(contactInformationDisplay_, SWT.BORDER);
				nameText_.setEditable(false);
				nameText_.setBounds(127, 28, 159, 19);
				formToolkit.adapt(nameText_, true, true);
			}
			/*{
				telephoneText_ = new Text(contactInformationDisplay_,
						SWT.BORDER);
				telephoneText_.setEditable(false);
				telephoneText_.setBounds(127, 103, 159, 19);
				formToolkit.adapt(telephoneText_, true, true);
			}*/
			/*
			{
				CLabel lblEmail_ = new CLabel(contactInformationDisplay_,
						SWT.NONE);
				lblEmail_.setBackground(SWTResourceManager
						.getColor(SWT.COLOR_GRAY));
				lblEmail_.setBounds(10, 78, 81, 19);

				//Contact Email
				lblEmail_.setText("Email:");
			}
			{
				emailText_ = new Text(contactInformationDisplay_, SWT.BORDER);
				emailText_.setEditable(false);
				emailText_.setBounds(127, 78, 159, 19);
				formToolkit.adapt(emailText_, true, true);
			}
			*/
			
			{
				comboEmailList = new Combo(contactInformationDisplay_, SWT.READ_ONLY);
				comboEmailList.setVisibleItemCount(8);
				comboEmailList.setItems(new String[] {"Email"});
				comboEmailList.setEnabled(false);
				comboEmailList.addSelectionListener(new SelectionAdapter() {
					@Override
					public void widgetSelected(SelectionEvent e) {
						System.out.print("\nIn email drop down. ");
						
						Combo getSelectEmailInfo = (Combo) e.getSource();
						System.out.println("Selected Email is: " + getSelectEmailInfo.getText());
						int selected = getSelectEmailInfo.getSelectionIndex();
						ArrayList<Combo> obj = (ArrayList<Combo>) getSelectEmailInfo.getData();
						Combo selectedEmailCombo = obj.get(selected);
						emailAddressvectorList_.add((EmailAddress) selectedEmailCombo.getData());


					}
				});
				/*
				comboEmailList.addFocusListener(new FocusListener() {

					@Override
					public void focusGained(FocusEvent arg0) {
						int liIndex = comboEmailList.getSelectionIndex();
						if(liIndex > -1)
						{
							String lStrEmail = comboEmailList.getItem(liIndex);
							if(lStrEmail == null)
							{
								lStrEmail = "";
							}
							emailText_.setText(lStrEmail);
							emailText_.update();
							logger.debug("Attempted to redraw email field:" );
						}
					}

					@Override
					public void focusLost(FocusEvent arg0) {
						
					}
					
				});*/
				comboEmailList.setBounds(127, 171, 159, 49);
				comboEmailList.select(0);
			}
			{
				Label lblEmailcombolabel = new Label(contactInformationDisplay_, SWT.NONE);
				lblEmailcombolabel.setBounds(10, 174, 81, 19);
				formToolkit.adapt(lblEmailcombolabel, true, true);
				lblEmailcombolabel.setText("EmailComboList");
			}
			{
				comboAddressList = new Combo(contactInformationDisplay_, SWT.READ_ONLY);
				comboAddressList.setEnabled(false);
				comboAddressList.addSelectionListener(new SelectionAdapter() {
					@Override
					public void widgetSelected(SelectionEvent e) {
						System.out.println("In address drop down...");
						Combo getSelectAddressInfo = (Combo) e.getSource();
						System.out.println("Selected Address is: " + getSelectAddressInfo.getText());
						int selected = getSelectAddressInfo.getSelectionIndex();
						ArrayList<Combo> obj = (ArrayList<Combo>) getSelectAddressInfo.getData();
						Combo selectedAddressCombo = obj.get(selected);
						addressVectorList_.add((Address) selectedAddressCombo.getData());
						
						//User can now enter the source address. 
						lblDestinationAddress.setVisible(true);
						txtEnterDestinationAddress.setVisible(true);
					}
				});
				comboAddressList.setBounds(127, 216, 159, 21);
				comboAddressList.setVisibleItemCount(8);
				comboAddressList.setItems(new String[] {"Address"});
				
				
				formToolkit.adapt(comboAddressList);
				formToolkit.paintBordersFor(comboAddressList);
				comboAddressList.select(0);
			}
			{
				comboTelephoneList = new Combo(contactInformationDisplay_, SWT.READ_ONLY);
				comboTelephoneList.setEnabled(false);
				comboTelephoneList.addSelectionListener(new SelectionAdapter() {
					@Override
					public void widgetSelected(SelectionEvent e) {
						System.out.println("In telephone drop down");
						Combo getSelectPhoneInfo = (Combo) e.getSource();
						System.out.println("Telephone is: " + getSelectPhoneInfo.getText());
						int selected = getSelectPhoneInfo.getSelectionIndex();
						ArrayList<Combo> obj = (ArrayList<Combo>) getSelectPhoneInfo.getData();
						Combo selectedPhoneCombo = obj.get(selected);
						phoneVectorList_.add((PhoneNumber) selectedPhoneCombo.getData());

					}
				});
				comboTelephoneList.setBounds(127, 266, 159, 21);
				comboTelephoneList.setVisibleItemCount(8);
				comboTelephoneList.setItems(new String[] {"Telephone"});
				formToolkit.adapt(comboTelephoneList);
				formToolkit.paintBordersFor(comboTelephoneList);
				comboTelephoneList.select(0);
			}
			{
				Label labelAddressList = new Label(contactInformationDisplay_, SWT.NONE);
				labelAddressList.setBounds(10, 219, 81, 19);
				labelAddressList.setText("Address List");
				formToolkit.adapt(labelAddressList, true, true);
			}
			{
				Label labelTelephoneList = new Label(contactInformationDisplay_, SWT.NONE);
				labelTelephoneList.setBounds(10, 268, 81, 19);
				labelTelephoneList.setText("Telephone List");
				formToolkit.adapt(labelTelephoneList, true, true);
			}
			{
				txtEnterDestinationAddress = new Text(contactInformationDisplay_, SWT.BORDER);
				txtEnterDestinationAddress.addMouseListener(new MouseAdapter() {
					@Override
					public void mouseDown(MouseEvent e) {
						txtEnterDestinationAddress.setText("");
					}
				});
				
				txtEnterDestinationAddress.setText("Enter Destination Address here...");
				txtEnterDestinationAddress.setBounds(127, 321, 299, 19);
				formToolkit.adapt(txtEnterDestinationAddress, true, true);
				txtEnterDestinationAddress.setVisible(false);
				
			}
			{
				lblDestinationAddress = new Label(contactInformationDisplay_, SWT.NONE);
				lblDestinationAddress.setBounds(10, 321, 111, 19);
				formToolkit.adapt(lblDestinationAddress, true, true);
				lblDestinationAddress.setText("Destination Address");
				lblDestinationAddress.setVisible(false);
			}
		}
		{
			Group buttonPanel = new Group(shlContactManagementSoftware_,
					SWT.NONE);
			buttonPanel.setBounds(0, 0, 807, 41);
			buttonPanel.setBackground(SWTResourceManager
					.getColor(SWT.COLOR_WIDGET_BACKGROUND));
			{
				Button btnUpdateContacts = new Button(buttonPanel, SWT.NONE);
				btnUpdateContacts.addSelectionListener(new SelectionAdapter() {
					@Override
					public void widgetSelected(SelectionEvent e) {
						logger.info("+ Has been clicked. Opening New Contact form.");
						AddContactMenu_GUI updateButtonContact = new AddContactMenu_GUI(
								shlContactManagementSoftware_, 1);

						updateButtonContact.setContact(currentlySelectedContact);
						updateButtonContact.setFirstName_(currentlySelectedContact.getFirstName());
						updateButtonContact.setLastName_(currentlySelectedContact.getLastName());
				
						//This list has the selectedItem from the Drop down.
						updateButtonContact.setAddressList_(addressVectorList_);
						updateButtonContact.setEmailList_(emailAddressvectorList_);
						updateButtonContact.setTelephoneList_(phoneVectorList_);
						updateButtonContact.open();
						
						addressVectorList_.clear();
						emailAddressvectorList_.clear();
						phoneVectorList_.clear();
						
						//Reseting the GUI so that the updated contact information is reflected. 
						resetCompleteGUI();
						
					}
				});
				btnUpdateContacts
						.setImage(SWTResourceManager
								.getImage("C:\\Documents and Settings\\pramakrishnan\\Desktop\\SW Project\\refresh.png"));
				btnUpdateContacts.setBounds(10, 10, 107, 23);
				btnUpdateContacts.setText("&Update Contact");
			}
			{
				// This is the Add contacts button
				Button btnadd = new Button(buttonPanel, SWT.NONE);
				btnadd.addSelectionListener(new SelectionAdapter() {
					@Override
					public void widgetSelected(SelectionEvent e) {
						logger
								.info("+ Has been clicked. Opening New Contact form.");
						AddContactMenu_GUI addButton_newContact = new AddContactMenu_GUI(
								shlContactManagementSoftware_, 1);
						addButton_newContact.open();
						
						//reseting GUI so that newly added Contact is reflected in the drop downs.
						resetCompleteGUI();
					}
				});
				btnadd.setBounds(123, 10, 68, 23);
				btnadd.setText("&Add");
			}
			{// This is the delete button
				btnDeleteGroup_ = new Button(buttonPanel, SWT.NONE);
				btnDeleteGroup_.setToolTipText("Deletes the selected contact");
				btnDeleteGroup_
						.setImage(SWTResourceManager
								.getImage("C:\\Documents and Settings\\pramakrishnan\\Desktop\\SW Project\\cancel.png"));
				btnDeleteGroup_.addSelectionListener(new SelectionAdapter() {
					@Override
					public void widgetSelected(SelectionEvent e) {
						
						Contact selectedContact = (Contact) selectedTreeItem
						.getData(selectedTreeItem.getText());
						
						logger.info("Deleting a contact..");
						
						int liResult = JOptionPane.showConfirmDialog(null, 
								"Are you sure you want to remove: " 
								+ selectedContact.getFirstName() + " " 
								+ selectedContact.getLastName() + 
								" permanently?",
								"Delete Selected Contact", 
								JOptionPane.YES_NO_OPTION);
						
						if(liResult == JOptionPane.YES_OPTION)
						{
							try {
								EngineUtil.deleteContact(selectedContact);
							} catch (SQLException contactDeleteError) {
								System.out.println("Error deleting Contact.");
								contactDeleteError.printStackTrace();
							}
							
							resetCompleteGUI();
						}
					}
				});
				btnDeleteGroup_.setForeground(SWTResourceManager
						.getColor(SWT.COLOR_WIDGET_FOREGROUND));
				btnDeleteGroup_.setBounds(197, 10, 68, 23);
				btnDeleteGroup_.setText("&Delete");
			}
			


		}

	}

	/**
	 * Reset the whole ContactForm
	 */
	private void resetCompleteGUI(){
		
		Point oldShellLocationSize = shlContactManagementSoftware_.getSize();
		Point oldShellLocation = shlContactManagementSoftware_.getLocation();
		shlContactManagementSoftware_.dispose();
		shlContactManagementSoftware_ = new Shell();
		shlContactManagementSoftware_.setLocation(oldShellLocation);
		shlContactManagementSoftware_.setSize(oldShellLocationSize);
		
		ContactFormGUI cfg = new ContactFormGUI();
		cfg.open();
		shlContactManagementSoftware_.dispose();
	}
	
	
	/**
	 * All Contacts for the logged in Application User.
	 * @param contactArray
	 */
	private void createContactArrayList(Contact[] contactArray){
		
		try {
			contactArrayList_.clear();
			if (contactArray != null) {

				for (Contact currentContact : contactArray) {
					contactArrayList_.add(currentContact);
				}
			} else if (contactArray == null) {
				logger.info("No Contact avaliable. Contact Array is null");
			}
		} catch (ArrayIndexOutOfBoundsException contactArrayOutOBound) {
			logger.error("The database did not return any contacts.");
		} catch (NullPointerException contactObjectNull) {
			logger.error("No contact is returned for the Application user.");
		}
		
	}
	
	
	/**
	 * Display all the contact per Contact Group name.
	 * @param contactGroupItem
	 * @param contactArrayPerGroup
	 * @return
	 */
	protected TreeItem createContactItems(TreeItem contactGroupItem,
			ArrayList<Contact> contactArrayPerGroup) {

		int currentContactItemCount = 1;

		Enumeration<Contact> enumerateContactArray = Collections
				.enumeration(contactArrayPerGroup);
		
		// Add contacts to the Contact group
		while (enumerateContactArray.hasMoreElements()) {

			TreeItem contactItem_ = new TreeItem(contactGroupItem, SWT.NONE);
			contactItem_.setItemCount(0);

			// Display the name of the contact in the Contact Item.
			// contactItem_.setText(contactArrayPerGroup_.get(0)
			// .getFirstName());
			Contact currentContact = (Contact) enumerateContactArray
					.nextElement();
			// contactItem_.setText("contact1: " + currentContactItemCount);
			contactItem_.setText(currentContact.getFirstName() + " "
					+ currentContact.getLastName());
			contactItem_.setData(contactItem_.getText(), currentContact);

			currentContactItemCount++;
		}

		//Save the Contact Information for every Contact Tree Item.
		contactGroupItem.setData(contactGroupItem.getText(),
				contactArrayPerGroup);

		// contactGroupItem.clear(9, false);

		// TreeItem item = contactGroupItem.getItem(1);

		// Stores all Contacts in a Contact Group.
		return contactGroupItem;

	}

	
	/**
	 * unimplemented
	 * Delete the Contact from a Contact Group.
	 * @param selectedContactGroupItem
	 * @param selectedContactName
	 * @return
	 */
//	protected boolean deleteContactFromContactGroup(
//		Tree selectedContactGroupItem, TreeItem selectedContactName) {
//		selectedContactName.clearAll(true);
//		// selectedContactName.clear(3, true);
//		// contactItem_.clear(index, all);
//		return true;
//	}

	
	/**
	 * Check if a Contact Belongs to one of the Contact Group.
	 * @param contactGroups
	 * @param matchContactGroup
	 * @return findMatch
	 */
	public boolean findTagMatch(Vector contactGroups,
			String matchContactGroup) {
		boolean findMatch = false;
		//Collection of available Contact Groups
		/*
		Enumeration enumerateContactGroup = Collections
				.enumeration(contactGroups);
		

		while (enumerateContactGroup.hasMoreElements()) {
			String currentContactGroupName = (String) enumerateContactGroup
					.nextElement();

			if (currentContactGroupName.equals(matchContactGroup)) {
				findMatch = true;
			}

		}
		*/
		
		java.util.ListIterator lListIterator = contactGroups.listIterator();
		
		while(lListIterator.hasNext())
		{
			TagForContact lTempTag = new TagForContact();
			lTempTag = (TagForContact)lListIterator.next();
			if(lTempTag.getSTag() != null && lTempTag.getSTag().equals(matchContactGroup))
			{
				return true;
			}
		}
		
		
		
		return findMatch;
	}

	
	public void testContactList() {

		// Contact 1--------------------------------->
		Contact c1 = new Contact("first", "last", "middle", "suff", "pref",
				"com", "title", true);
		c1.setIdContact(1);
		Vector<String> c1Tags = new Vector<String>();
		Vector<Address> c1address = new Vector<Address>();
		Vector<PhoneNumber> c1phone = new Vector<PhoneNumber>();
		Vector<EmailAddress> c1email = new Vector<EmailAddress>();

		c1Tags.add("Group1");
		c1Tags.add("Group2");
		c1address.add(new Address("contact1address1", "street2", "street3", "ctry1", "zip1",
				"prov1", "city1", "Residence"));
		c1address.add(new Address("contact1address22","street22", "street32", "ctry2", "zip2",
				"prov2", "city2",  "Work"));
		c1address.add(new Address("55 Station Landing APT 308","street22", "street32", "US", "02155",
				"MA", "Boston",  "Work"));
		c1phone.add(new PhoneNumber("1", "Cellular"));
		c1phone.add(new PhoneNumber("2", "Work"));
		c1email.add(new EmailAddress("c1@c1.com", "Work"));
		c1email.add(new EmailAddress("c1@c2.com", "Residence"));
		c1email.add(new EmailAddress("c1@c3.com", "Work"));
		c1email.add(new EmailAddress("c1@c4.com", "Random"));
		c1email.add(new EmailAddress("c1@c5.com", "Random"));
		c1email.add(new EmailAddress("c1@c6.com", ""));
		c1email.add(new EmailAddress("c1@c7.com", ""));
		c1email.add(new EmailAddress("c1@c8.com", ""));
		c1email.add(new EmailAddress("c1@c9.com", ""));
		c1email.add(new EmailAddress("c1@c10.com", ""));
		c1email.add(new EmailAddress("c1@c11.com", ""));
		c1email.add(new EmailAddress("c1@c12.com", ""));
		c1email.add(new EmailAddress("c1@c13.com", ""));
		c1.setTags(c1Tags);
		c1.setAddresses(c1address);
		c1.setPhoneNumbers(c1phone);
		c1.setEmails(c1email);

		// Contact 2--------------------------------->
		Contact c2 = new Contact("first2", "last2", "middle2", "suff2",
				"pref2", "com2", "title2", true);
		c2.setIdContact(2);
		Vector<String> c2Tags = new Vector<String>();
		Vector<Address> c2address = new Vector<Address>();
		Vector<PhoneNumber> c2phone = new Vector<PhoneNumber>();
		Vector<EmailAddress> c2email = new Vector<EmailAddress>();

		c2Tags.add("Group1");
		c2address.add(new Address("contact2address1", "", "", "", "",
				"", "", ""));
		c2address.add(new Address("contact2address2", "", "", "", "",
				"", "", ""));
		c2phone.add(new PhoneNumber("1", ""));
		c2phone.add(new PhoneNumber("2", ""));
		c2email.add(new EmailAddress("c2@c1.com", ""));
		c2email.add(new EmailAddress("c2@c2.com", ""));
		c2.setTags(c2Tags);
		c2.setAddresses(c2address);
		c2.setPhoneNumbers(c2phone);
		c2.setEmails(c2email);

		// Contact 3--------------------------------->
		Contact c3 = new Contact("first3", "last3", "middle3", "suff3",
				"pref3", "com3", "title3", true);
		c3.setIdContact(3);
		Vector<String> c3Tags = new Vector<String>();
		Vector<Address> c3address = new Vector<Address>();
		Vector<PhoneNumber> c3phone = new Vector<PhoneNumber>();
		Vector<EmailAddress> c3email = new Vector<EmailAddress>();

		c3Tags.add("Group1");
		c3Tags.add("Group3");
		c3address.add(new Address("contact3address1", "", "", "", "",
				"", "", ""));
		c3address.add(new Address("contact3address2", "", "", "", "",
				"", "", ""));
		c3phone.add(new PhoneNumber("1", ""));
		c3phone.add(new PhoneNumber("2", ""));
		c3email.add(new EmailAddress("c3@c1.com", ""));
		c3email.add(new EmailAddress("c3@c2.com", ""));
		c3.setTags(c3Tags);
		c3.setAddresses(c3address);
		c3.setPhoneNumbers(c3phone);
		c3.setEmails(c3email);

		// Contact 4--------------------------------->
		Contact c4 = new Contact("first4", "last4", "middle4", "suff4",
				"pref4", "com4", "title4", true);
		c4.setIdContact(4);
		Vector<String> c4Tags = new Vector<String>();
		Vector<Address> c4address = new Vector<Address>();
		Vector<PhoneNumber> c4phone = new Vector<PhoneNumber>();
		Vector<EmailAddress> c4email = new Vector<EmailAddress>();

		c4Tags.add("Group2");
		c4Tags.add("Group4");
		c4address.add(new Address("contact4address1", "", "", "", "",
				"", "", ""));
		c4address.add(new Address("contact4address2", "", "", "", "",
				"", "", ""));
		c4phone.add(new PhoneNumber("1", ""));
		c4phone.add(new PhoneNumber("2", ""));
		c4email.add(new EmailAddress("c4@c1.com", ""));
		c4email.add(new EmailAddress("c4@c2.com", ""));
		c4.setTags(c4Tags);
		c4.setAddresses(c4address);
		c4.setPhoneNumbers(c4phone);
		c4.setEmails(c4email);

		//Adding Contact to ArrayList------------------------->
		contactArrayList_.add(c1);
		contactArrayList_.add(c2);
		contactArrayList_.add(c3);
		contactArrayList_.add(c4);

		System.out.println("Added 4 test contacts");
	}

	/**
	 * Gets the Contact Information of the contact to be searched
	 * @param contactToSearch
	 * @return
	 */
	public void getSearchContact(String contactToSearch){
		
		//For every search clear previous search result and start fresh.
		comboAddressList.removeAll();
		comboEmailList.removeAll();
		comboTelephoneList.removeAll();
		
		Enumeration<Contact> contactEnumerator = Collections.enumeration(contactArrayList_);
		
		while (contactEnumerator.hasMoreElements()){
			
			Contact currentContact = (Contact) contactEnumerator.nextElement();
			String contactFName = currentContact.getFirstName().toLowerCase().trim();
			String contactLName = currentContact.getLastName().toLowerCase().trim();
			CharSequence contactNameToSearch = contactToSearch.toLowerCase().trim();
			
			if (contactFName.contains(contactNameToSearch) || contactLName.contains(contactNameToSearch)){
				nameText_.setText(contactFName);
				populateDropDownList(comboAddressList, currentContact.getAddresses());
				populateDropDownList(comboEmailList, currentContact.getEmails());
				populateDropDownList(comboTelephoneList, currentContact.getPhoneNumbers());
				currentlySelectedContact = currentContact;
			} else {
				System.out.println("Could not find Contact  or Contact does not exist.");
			}
			
		}
		
	}

	/**
	 * List the Contact Email Address, Phone, Address etc.
	 * @param listObject
	 * @param listItems
	 * @return
	 */
	public Combo populateDropDownList(Combo listObject, Vector<?> listItems) {
		
		int itemIndex = 0;
		Enumeration enumerateListItems = Collections.enumeration(listItems);
		ArrayList<Combo> comboArrayListData = new ArrayList<Combo>();
		
		while (enumerateListItems.hasMoreElements()) {

			Object currentListItem = enumerateListItems.nextElement();
	
			
			if (currentListItem instanceof EmailAddress) {
				Combo currentEmailCombo = new Combo(shlContactManagementSoftware_, 0);
				
				currentEmailCombo.setData(currentListItem);				
//				String fullEmailAddress = currentListItem.toString();
				
				String fullEmailAddress = ((EmailAddress) currentListItem).getEmailAddress();
				
				listObject.add(fullEmailAddress);
//				listObject.setData(currentEmailCombo);
				comboArrayListData.add(currentEmailCombo);
				comboEmailList.setEnabled(true);
				
			} else if (currentListItem instanceof PhoneNumber) {
				Combo currentPhoneCombo = new Combo(shlContactManagementSoftware_, 0);
				currentPhoneCombo.setData(currentListItem);
				
//				String fullPhone = currentListItem.toString();
				String fullPhone = ((PhoneNumber) currentListItem).getPhoneNumber();
				
				listObject.add(fullPhone);
//				listObject.add(((PhoneNumber) currentListItem).getPhoneNumber());
//				listObject.setData(currentPhoneCombo);
				comboArrayListData.add(currentPhoneCombo);
				comboTelephoneList.setEnabled(true);
				
			} else if (currentListItem instanceof Address) {

				Combo currentAddressCombo = new Combo(shlContactManagementSoftware_, 0);
				currentAddressCombo.setData(currentListItem);	
				
//				String fullAddress = currentListItem.toString();
				String streetAddrs =  ((Address) currentListItem).getStreet1();
				String city = ((Address) currentListItem).getCity();
				String province = ((Address) currentListItem).getProvince();
				String zipcode = ((Address) currentListItem).getZipCode();
				String country = ((Address) currentListItem).getCountry();
				
				String fullAddress = streetAddrs + ", " + city + ", " + province +", " + zipcode +", " + country;
				
				listObject.add(fullAddress);
//				listObject.add(((Address) currentListItem).getStreet1());
//				listObject.setData(currentAddressCombo);
				comboArrayListData.add(currentAddressCombo);
				comboAddressList.setEnabled(true);
				
			}
			itemIndex++;
		}
		listObject.setData(comboArrayListData);
		return listObject;
	}
}
